// poj2449
// 题意：给定一个n(<=1000)个点，m(<=100000)条有向有权边的图，给定起点和
//       终点，问可以有环k(<=1000)短路的长度，如果没有输出-1。
//
// 题解：有环k短路和无环k短路都有专门的算法。这道题是用了A*。
//       启发函数为：到当前这个点的距离+从这个出发到终点最短距离。
//       然后用这个启发函数在优先队列不断往外拓展。然后再记录每个点
//       出队列的次数，如果当前这个点出了k次且是终点就是答案。
//
//       另外这道题如果起点和终点是同一个点，最短路不算0。
//
// run: $exec < input
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>

int const maxn = 1007;
int const maxm = 200007;
long long const inf  = (1ll) << 40;
int head[maxn], end_point[maxm], next[maxm], cost[maxm];
bool rev[maxm];
int alloc = 2;
long long dist[maxn];
int count[maxn];
int n, m, s, t, k;

void add_edge(int u, int v, int c)
{
	end_point[alloc] = v; cost[alloc] = c; rev[alloc] = false;
	next[alloc] = head[u]; head[u] = alloc++;

	end_point[alloc] = u; cost[alloc] = c; rev[alloc] = true;
	next[alloc] = head[v]; head[v] = alloc++;
}

void dijkstra(int source)
{
	std::fill(dist, dist + n + 1, inf);
	dist[source] = 0;
	typedef std::pair<long long, int> cost_end;
	std::priority_queue<cost_end, std::vector<cost_end>, std::greater<cost_end> > pq;
	pq.push(std::make_pair(0, source));
	while (!pq.empty()) {
		cost_end tmp = pq.top(); pq.pop();
		int u = tmp.second;
		if (dist[u] < tmp.first) continue;

		for (int p = head[u]; p; p = next[p]) {
			if (!rev[p]) continue;
			int v = end_point[p];
			long long c = cost[p];
			if (dist[v] > dist[u] + c) {
				dist[v] = dist[u] + c;
				pq.push(std::make_pair(dist[v], v));
			}
		}
	}
}

struct state
{
	state(int u, long long dis) : u(u), dis(dis) {}
	int u;
	long long dis;
};

bool operator<(state const & a, state const & b)
{
	return a.dis + dist[a.u] > b.dis + dist[b.u];
}

int astar(int source, int target, int k)
{
	state start(source, 0);
	std::priority_queue<state> pq;
	pq.push(start);
	while (!pq.empty()) {
		state now = pq.top(); pq.pop();
		count[now.u]++;
		if (count[now.u] > k) continue;
		if (count[now.u] == k && now.u == target) return now.dis;
		for (int p = head[now.u]; p; p = next[p]) {
			int v = end_point[p];
			long long c = cost[p];
			if (rev[p]) continue;
			state tmp(v, now.dis + c);
			pq.push(tmp);
		}
	}
	return -1;
}

int main()
{
	std::ios::sync_with_stdio(false);
	std::cin >> n >> m;
	for (int i = 0, x, y, z; i < m; i++) {
		std::cin >> x >> y >> z;
		add_edge(x, y, z);
	}
	std::cin >> s >> t >> k;
	if (s == t) k++;

	dijkstra(t);

	std::cout << astar(s, t, k) << '\n';
}

